﻿Imports BlogML.Xml
Imports DotNetNuke.Modules.Blog.Business
Imports System.Linq
Imports System.Xml
Imports System.IO
Imports DotNetNuke.Modules.Blog.Settings
Imports DotNetNuke.Services.Localization

Friend Class BlogEngineReader
  Inherits GraffitiReader

  Protected Overrides Function GetNewBlogEntry(ByVal objPostML As BlogMLPost) As EntryInfo
    Return New EntryInfo() With { _
              .Title = objPostML.Title, _
              .Description = GetSummary(objPostML), _
              .Entry = GetEntry(objPostML)}
  End Function

  Private Shared Function GetSummary(ByVal objPostML As BlogMLPost) As String
    Dim summary As String = objPostML.Excerpt.Text
    If Not objPostML.HasExcerpt AndAlso objPostML.Content.Text.Contains("<p>[more]</p>") Then
      Dim content As String = objPostML.Content.Text
      summary = content.Substring(0, content.IndexOf("<p>[more]</p>"))
    End If
    Return summary
  End Function

  Private Shared Function GetEntry(ByVal objPostML As BlogMLPost) As String
    Return objPostML.Content.Text.Replace("<p>[more]</p>", String.Empty)
  End Function
End Class
